<template>
	<view class="container">
		<!-- 顶部导航栏 -->
		<view class="nav-bar">
			<!-- <view class="back-icon" @click="goBack">
				<text class="iconfont">&#xe8b5;</text>
			</view> -->
			<view>
				<image class="back" src="/static/images/白色左箭头.png" mode="" @click="goBack"></image>
			</view>
			<text class="nav-title">选择车辆</text>
		</view>

		<!-- 车辆列表 -->
		<view class="car-list">
			<view class="car-item" v-for="(car, index) in cars" :key="index">
				<view class="car-info">
					<image :src="car.image" mode="aspectFill" class="car-image"></image>
					<view class="car-details">
						<view class="car-model">
							<text class="label">车型：</text>
							<text class="value">{{ car.model }}</text>
						</view>
						<view class="car-plate">
							<text class="label">车牌：</text>
							<text class="value">{{ car.plate }}</text>
						</view>
					</view>
				</view>
				<!-- <image src="/static/xiche/组 5 拷贝@3x.png"></image> -->
				<image :src="car.isSelected ? '/static/home/wash/组 5 拷贝@3x.png' : '/static/home/wash/椭圆 4 拷贝 2@3x.png'"
					mode="aspectFit" class="select-icon" @click.stop="toggleSelect(index)"></image>
			</view>
		</view>

		<!-- 添加车辆按钮 -->
		<view class="add-car-btn" @click="addCar">
			<image src="/static/home/wash/加号@3x.png" mode="aspectFit" class="add-icon"></image>
			<text>添加车辆</text>
		</view>
	</view>
</template>

<script setup>
	import {
		ref
	} from 'vue';

	const cars = ref([{
			model: '奔驰-GR',
			plate: '豫M35468',
			image: '/static/user3/car2.jpg',
			isSelected: false
		},
		{
			model: '奔驰-GR',
			plate: '豫M35468',
			image: '/static/user3/car2.jpg',
			isSelected: false
		}
	]);

	const goBack = () => {
		uni.navigateBack();
	};

	const toggleSelect = (index) => {
		cars.value[index].isSelected = !cars.value[index].isSelected;
	};

	const addCar = () => {
		uni.navigateTo({
			url: '/pages/addcar/addcar'
		});
	};
</script>

<style scoped>
	.container {
		min-height: 100vh;
		background: #F8F8F8;
	}

	.back {
		position: absolute;
		left: 30rpx;
		top: 50rpx;
		width: 15px;
		height: 15px;
		z-index: 2;
	}

	.nav-bar {
		display: flex;
		/* align-items: center; */
		justify-content: center;
		height: 228rpx;
		padding: 0 30rpx;
		background: #4080FF;
		color: #fff;
	}

	.back-icon {
		font-size: 40rpx;
	}

	.nav-title {
		font-size: 34rpx;
		font-weight: 500;
		margin: 0 auto;
		height: 88rpx;
		margin-top: 40rpx;
	}

	.right-icons {
		display: flex;
		gap: 20rpx;
	}

	.icon {
		width: 48rpx;
		height: 48rpx;
	}

	.car-list {
		padding: 20rpx;
		margin-top: -140rpx;
	}

	.car-item {
		display: flex;
		justify-content: space-between;
		align-items: center;
		background: #FFFFFF;
		padding: 30rpx;
		margin-bottom: 20rpx;
		border-radius: 20rpx;
	}

	.car-info {
		display: flex;
		align-items: center;
		gap: 30rpx;
	}

	.car-image {
		width: 120rpx;
		height: 120rpx;
		border-radius: 60rpx;
	}

	.car-details {
		display: flex;
		flex-direction: column;
		gap: 10rpx;
	}

	.car-model,
	.car-plate {
		display: flex;
		align-items: center;
	}

	.label {
		color: #333333;
		font-size: 28rpx;
	}

	.value {
		color: #333333;
		font-size: 28rpx;
		font-weight: 500;
	}

	.select-icon {
		width: 40rpx;
		height: 40rpx;
	}

	.add-car-btn {
		position: fixed;
		bottom: 40rpx;
		left: 40rpx;
		right: 40rpx;
		height: 88rpx;
		background: #4080FF;
		border-radius: 44rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		color: #FFFFFF;
		font-size: 32rpx;
	}

	.add-icon {
		width: 32rpx;
		height: 32rpx;
		margin-right: 10rpx;
	}
</style>